/*
 * @Author: guandeshen 295570679@qq.com
 * @Date: 2024-08-20 11:05:08
 * @LastEditors: guandeshen 295570679@qq.com
 * @LastEditTime: 2024-09-02 15:14:25
 * @FilePath: /task-admin/src/router/index.ts
 * @Description:
 *
 * Copyright (c) 2024 by RSC, All Rights Reserved.
 */
import { createRouter, createWebHashHistory, RouteRecordRaw } from "vue-router";
export const Layout = () => import("@/layout/index.vue");

// 静态路由
export const constantRoutes: RouteRecordRaw[] = [
  {
    path: "/redirect",
    component: Layout,
    meta: { hidden: true },
    children: [
      {
        path: "/redirect/:path(.*)",
        component: () => import("@/views/redirect/index.vue"),
      },
    ],
  },

  {
    path: "/login",
    component: () => import("@/views/login/index.vue"),
    meta: { hidden: true },
  },

  {
    path: "/personalInfo",
    component: Layout,
    redirect: "/personalInfo/index",
    meta: {
      hidden: true,
      alwaysShow: false,
    },
    children: [
      {
        path: "index",
        component: () => import("@/views/personalInfo/index.vue"),
        meta: {
          title: "personalInfo",
          hidden: true,
        },
      },
    ],
  },

  {
    path: "/changePassword",
    component: Layout,
    redirect: "/changePassword/index",
    meta: {
      hidden: true,
      alwaysShow: false,
    },
    children: [
      {
        path: "index",
        component: () => import("@/views/changePassword/index.vue"),
        meta: {
          title: "changePassword",
          hidden: true,
        },
      },
    ],
  },

  {
    path: "/",
    name: "/",
    component: Layout,
    redirect: "/dashboard",
    children: [
      {
        path: "dashboard",
        component: () => import("@/views/dashboard/index.vue"),
        name: "Dashboard", // 用于 keep-alive, 必须与SFC自动推导或者显示声明的组件name一致
        meta: {
          title: "dashboard",
          icon: "home",
          affix: true,
          keepAlive: true,
          alwaysShow: false,
        },
      },
      {
        path: "401",
        component: () => import("@/views/error-page/401.vue"),
        meta: { hidden: true },
      },
      {
        path: "404",
        component: () => import("@/views/error-page/404.vue"),
        meta: { hidden: true },
      },
    ],
  },

  // {
  //   path: "/projectAndLocation",
  //   component: Layout,
  //   meta: {
  //     title: "projectAndLocation",
  //     icon: "project",
  //     alwaysShow: false,
  //     keepAlive: false,
  //     hidden: false,
  //   },
  //   children: [
  //     {
  //       path: "index",
  //       component: () => import("@/views/project/index.vue"),
  //       meta: {
  //         title: "projectLocation",
  //         icon: "project",
  //         alwaysShow: false,
  //       },
  //     },
  //   ],
  // },

  // {
  //   path: "/WBS",
  //   component: Layout,
  //   meta: {
  //     alwaysShow: false,
  //   },
  //   children: [
  //     {
  //       path: "index",
  //       component: () => import("@/views/wbs/index.vue"),
  //       meta: {
  //         title: "WBS",
  //         icon: "WBS",
  //       },
  //     },
  //   ],
  // },

  // {
  //   path: "/Tasks",
  //   component: Layout,
  //   meta: {
  //     alwaysShow: false,
  //   },
  //   children: [
  //     {
  //       path: "index",
  //       component: () => import("@/views/task/index.vue"),
  //       meta: {
  //         title: "Tasks",
  //         hidden: false,
  //         keepAlive: true,
  //         icon: "task",
  //       },
  //     },
  //     {
  //       path: "editTask/:id",
  //       name: "editTask",
  //       component: () => import("@/views/task/editTask.vue"),
  //       meta: {
  //         title: "editTask",
  //         hidden: true,
  //         keepAlive: true,
  //       },
  //     },
  //     {
  //       path: "editTask",
  //       name: "addTask",
  //       component: () => import("@/views/task/editTask.vue"),
  //       meta: {
  //         title: "addTask",
  //         hidden: true,
  //         keepAlive: true,
  //       },
  //     },
  //     {
  //       path: "taskDetails",
  //       name: "taskDetails",
  //       component: () => import("@/views/task/taskDetails.vue"),
  //       meta: {
  //         title: "taskDetails",
  //         hidden: true,
  //         keepAlive: false,
  //       },
  //     },
  //     // {
  //     //   path: "taskDetails/:id",
  //     //   name: "taskDetails",
  //     //   component: () => import("@/views/task/taskDetails.vue"),
  //     //   meta: {
  //     //     title: "Task Details",
  //     //     hidden: true,
  //     //     keepAlive: true,
  //     //   },
  //     // },
  //   ],
  // },

  // {
  //   path: "/LogBookReport",
  //   component: Layout,
  //   meta: {
  //     alwaysShow: false,
  //   },
  //   children: [
  //     {
  //       path: "index",
  //       component: () => import("@/views/log-book/index.vue"),
  //       meta: {
  //         title: "logBookReport",
  //         icon: "log",
  //       },
  //     },
  //   ],
  // },

  // {
  //   path: "/Assets",
  //   component: Layout,
  //   meta: {
  //     alwaysShow: false,
  //   },
  //   children: [
  //     {
  //       path: "index",
  //       component: () => import("@/views/assets-list/index.vue"),
  //       meta: {
  //         title: "assets",
  //         icon: "assets",
  //       },
  //     },
  //   ],
  // },
  // {
  //   path: "/Teams",
  //   component: Layout,
  //   meta: {
  //     alwaysShow: false,
  //   },
  //   children: [
  //     {
  //       path: "index",
  //       component: () => import("@/views/teams/index.vue"),
  //       meta: {
  //         title: "teams",
  //         icon: "team",
  //       },
  //     },
  //   ],
  // },

  // 外部链接
  // {
  //   path: "/external-link",
  //   component: Layout,
  //   children: [ {
  //       component: () => import("@/views/external-link/index.vue"),
  //       path: "https://www.cnblogs.com/haoxianrui/",
  //       meta: { title: "外部链接", icon: "link" },
  //     },
  //   ],
  // },
  // 多级嵌套路由
  // {
  //   path: "/system",
  //   component: Layout,
  //   redirect: "/system/role",
  //   name: "Nested",
  //   meta: { title: "system", icon: "menu", alwaysShow: true, keepAlive: true },
  //   children: [
  //     {
  //       path: "role",
  //       component: () => import("@/views/system/role/index.vue"),
  //       name: "Role",
  //       meta: { title: "role", icon: "", alwaysShow: true, keepAlive: true },
  //     },
  //     {
  //       path: "menu",
  //       component: () => import("@/views/system/menu/index.vue"),
  //       name: "Menu",
  //       meta: { title: "menu", icon: "", alwaysShow: true, keepAlive: true },
  //     },
  //   ],
  // },
];

/**
 * 创建路由
 */
const router = createRouter({
  history: createWebHashHistory(),
  routes: constantRoutes,
  // 刷新时，滚动条位置还原
  scrollBehavior: () => ({ left: 0, top: 0 }),
});

/**
 * 重置路由
 */
export function resetRouter() {
  router.replace({ path: "/login" });
}

export default router;
